package com.ycd.Servlet;

import com.ycd.Entity.LanMuEntity;
import com.ycd.Entity.XinWenEntity;
import com.ycd.Service.LanMuEntityService;
import com.ycd.Service.XinWenEntityService;
import com.ycd.Service.impl.LanMuEntityServiceImpl;
import com.ycd.Service.impl.XinWenEntityServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Description 登录展示
 * @Author ycd
 * @Date : 2022/3/16 17:13
 * @Version : 1.0
 */
@WebServlet("/html/main.html")
public class ShowMainHtmlServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");


        //查询栏目
        LanMuEntityService lanMuEntityService=new LanMuEntityServiceImpl();
        List<LanMuEntity> lanMuEntities = lanMuEntityService.queryAll();

        LanMuEntity lanMuEntity=lanMuEntities.get(0);
        int LanMuEntity_id=lanMuEntity.getId();


        String lanMuEntitiesid = req.getParameter("lanMuEntitiesid");

        if (lanMuEntitiesid != null){
            LanMuEntity_id=Integer.parseInt(lanMuEntitiesid);
        }

        XinWenEntityService xinWenEntityService=new XinWenEntityServiceImpl();
        List<XinWenEntity>   news=xinWenEntityService.queryNewsByChannel(LanMuEntity_id);



        req.setAttribute("lanMuEntities",lanMuEntities);
        req.setAttribute("news",news);

        req.getRequestDispatcher("main.jsp").forward(req,resp);


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
